﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Snowy.Dtos;
using Snowy.Extensions;
using Snowy.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Snowy.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class CaptchaController : ControllerBase
    {
        private readonly IMemoryCache _memoryCache;
        private readonly IWebHostEnvironment _env;
        private readonly AppSettings _settings;
        private readonly ClickWordCaptcha _captcha;
        private readonly ILogger  _logger;
        public CaptchaController(IMemoryCache memoryCache, ClickWordCaptcha captcha, IWebHostEnvironment env,  IOptions<AppSettings> options, ILogger<CaptchaController> logger)
        {
            _captcha = captcha;
            _logger = logger;
            _memoryCache= memoryCache  ;
            _env = env;
            _settings = options.Value;
            _logger = logger;


        }
        [HttpGet("get")]
        public  ActionResult CaptchaIsGood(CaptchaType captchaType)
        {
            ActionResult result = BadRequest(captchaType);
            switch (captchaType)
            {
                case CaptchaType.ClickWord:
                    result = Ok(_captcha.CreateCaptchaImage(_captcha.RandomCode(6), 310, 155));
                    break;
                default:
                    break;
            }
            return result;
        }
     
    }
}
